package com.augurit.gzcgwsp.smartformCsdlwj.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.HqlUtils;
import com.augurit.common.util.PageUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.lhsp.service.IProcessInstanceService;
import com.augurit.gzcgwsp.lhsp.web.form.LhspSendItemNoticeForm;
import com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService;
import com.augurit.gzcgwsp.sendNotice.service.IYwMtbjlshInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.smartformCsdlwj.convert.YwSrDlzyConvertor;
import com.augurit.gzcgwsp.smartformCsdlwj.dao.YwSSGgcsDao;
import com.augurit.gzcgwsp.smartformCsdlwj.dao.YwSrDlzyDao;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.DlzyYq;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwGgcs;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwSrDlzy;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwDlzyService;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.DlzyForm;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxTwoService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjclService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjcllistService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxTwoForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjclForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjcllistForm;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.dao.Jbpm4HistProcinstDao;
import com.augurit.wf.common.dao.Jbpm4HistTaskDao;
import com.augurit.wf.common.entity.Jbpm4HistProcinst;
import com.augurit.wf.common.entity.Jbpm4HistTask;
import com.augurit.wf.common.entity.WfBusInstance;
import com.augurit.wf.common.service.impl.WfBusClientServiceImpl;

/**
 * 目前这个类，只有与方欣的数据交换用到
 * @author Administrator  
 *
 */

@Service
@Transactional
public class YwDlzyServiceImpl extends WfBusClientServiceImpl<DlzyForm> implements IYwDlzyService{
	private static final Log log=LogFactory.getLog(YwCsdlwjServiceImpl.class);
    @Autowired
    private Jbpm4HistTaskDao jbpm4HistTaskDao;
    @Autowired
    private Jbpm4HistProcinstDao jbpm4HistProcinstDao;
	@Autowired
	private YwSrDlzyDao ywSrDlzyDao;
	@Autowired
	private YwSSGgcsDao ywSSGgcsDao;
    @Autowired
    private IYwComQyxxService ywComQyxxService;
    @Autowired
    private IYwComSjclService sjclService;
    @Autowired
	private IYwComSjcllistService ywComSjcllistService;
	@Autowired
	private IYwComSjclService ywComSjclService;
	@Autowired
	private IYwComQyxxTwoService ywComQyxxTwoService;
	@Autowired
    private IYwMtbjlshInfoService ywMtbjlshInfoService;
    @Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;
    @Autowired
    private IYwWebserviceForWbService ywWebserviceForWbService;
    @Autowired
    private IExchangeStateService exchangeStateService;
    @Autowired
    private IWfServiceEX wfServiceEX;
    @Autowired
    private IProcessInstanceService processInstanceService;
	
	/**
	 * ��������ȡForm����
	 */
	@Transactional(readOnly = true)
	public DlzyForm get(Long id) {
		YwSrDlzy entity = ywSrDlzyDao.get(id);
		DlzyForm form = YwSrDlzyConvertor.convertVoToForm(entity);
		String qybh = form.getQybh();
		if(StringUtils.isNotBlank(qybh)){
			YwComQyxxForm qyxxform = ywComQyxxService.get(Long.parseLong(form.getQybh()));
	        YwSrDlzyConvertor.convertQyxxFormToForm(qyxxform, form);
	        form.setSqdw(qyxxform.getSqdw());
		}        
		String days=this.getYqDays(null,form.getAcceptNo());
		form.setYqts(days);
		if(form.getLhspId() != null){//加载联合审批的信息
        	LhspSendItemNoticeForm sendItemNoticeForm = processInstanceService.get(form.getLhspId());
        	YwSrDlzyConvertor.convertSendItemNoticeFormToForm(sendItemNoticeForm, form);
        }
		form.setZsbh(entity.getZsbh());
        return form;
        //return YwSrDlzyConvertor.convertVoToForm(entity);
	}
	
	//通过案件号获得实体类
    public List<YwSrDlzy> getByAcceptNo(String acceptNo) {
    	String sql = "from YwSrDlzy t where t.acceptNo='" + acceptNo + "'";
        List<YwSrDlzy> entityList = ywSrDlzyDao.find(sql);
        return entityList;
    }
    
  //通过案件号获得公厕拆除实体类
    public List<YwGgcs> getWCCaseByAcceptNo(String acceptNo){
    	String sql = "from YwGgcs t where t.acceptNo='" + acceptNo + "'";
        List<YwGgcs> entityList = ywSSGgcsDao.find(sql);
        return entityList;
    }
	
    public void changeYslState(Long id,Long state,String yslThyy) {
    	StringBuffer sql = new StringBuffer();
    	sql.append("update YwSrDlzy t set t.ysl='"+state+"' ");
    	if(StringUtils.isNotBlank(yslThyy)){
    		sql.append(" ,t.yslThyy='"+yslThyy+"'");
    	}
    	sql.append(" where t.id="+id);
    	ywSrDlzyDao.getSession().createQuery(sql.toString()).executeUpdate();
    	System.out.println("道路占用收件");
    }
    
    //是否延期办理
    public void changeIsycbl(Long id, String state) {
    	YwSrDlzy entity = ywSrDlzyDao.get(id);
//    	entity.setIsycbl(state);
    	ywSrDlzyDao.save(entity);
	}
    
    /**
     * 设置该案件为咨询服务案件
     * @param id
     */
    public void changeIsZxfwaj(Long id) {
    	YwSrDlzy entity = ywSrDlzyDao.get(id);
//    	entity.setIsZxfwaj("Y");
    	ywSrDlzyDao.save(entity);
    }
	
    //保存结案时间
	public void endSave(Long id) {
		YwSrDlzy entity = ywSrDlzyDao.get(id);
    	entity.setJarq(new Date());
    	ywSrDlzyDao.save(entity);
	}
    
	public void delete(Long... ids) {
		ywSrDlzyDao.delete(ids);
	}

	/**
	 * �����������޸ĵ�Form�����б�
	 */
	public void save(DlzyForm... forms) {
		if(forms != null)
			for(DlzyForm form : forms)
				this.save(form);
	}
	
	/**
	 * �����������޸ĵ�Form����
	 */
	public void save(DlzyForm form){
		System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"+form.getSqdw());
		
        if (form == null) return;

		YwSrDlzy entity = new YwSrDlzy(); 
        if(form != null && form.getId() != null){
            entity = ywSrDlzyDao.get(form.getId());
            if (StringUtils.isBlank(entity.getAcceptNo()) || form.getAcceptNo().indexOf("XXXX") > 0) form.setAcceptNo(null);
        }else{
            entity = new YwSrDlzy(); 
            form.setAcceptNo(null);
        }
        
        //保存企业信息
        YwComQyxxForm qyxxForm = new YwComQyxxForm();
        if(StringUtils.isEmpty(form.getQybh())){
        	if(StringUtils.isNotBlank(form.getSqdw())){
            	YwComQyxxForm ywComQyxxForm = ywComQyxxService.getFormBySqdw(form.getSqdw(), form.getTemplateCode());
            	if(ywComQyxxForm != null){
            		qyxxForm = ywComQyxxForm;
            	}
            }
        }
        if(qyxxForm.getId() != null){
        	form.setQybh(qyxxForm.getId().toString());
        }
        
        YwSrDlzyConvertor.convertFormToQyxxForm(form, qyxxForm);
        qyxxForm.setTemplateCode(form.getTemplateCode());
        ywComQyxxService.update(qyxxForm);
        form.setQybh(qyxxForm.getId().toString());
        
      //保存施工单位信息表
        YwComQyxxTwoForm ywComQyxxTwoForm = new YwComQyxxTwoForm();
        if(StringUtils.isEmpty(form.getQybhTwo())){
        	if(StringUtils.isNotBlank(form.getZydw())){
        		YwComQyxxTwoForm ywComQyxxTwoForm2 = ywComQyxxTwoService.getFormBySqdwTwo(form.getZydw(), form.getTemplateCode());
            	if(ywComQyxxTwoForm2 != null){
            		ywComQyxxTwoForm = ywComQyxxTwoForm2;
            	}
            }
        }        
        YwSrDlzyConvertor.convertFormToQyxxTwoForm(form, ywComQyxxTwoForm);
        ywComQyxxTwoForm.setTemplateCodeTwo(form.getTemplateCode());
        ywComQyxxTwoService.update(ywComQyxxTwoForm);
        form.setQybhTwo(ywComQyxxTwoForm.getId().toString());
        
        boolean isNewForm = false;
        if (StringUtils.isBlank(form.getAcceptNo())) {
        	//生成政务中心统一查询编号 开始
			Map<String,String> serialNoAndPasswordMap = null;
        	if("Y".equals(form.getSendNotice())){//网办，1
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("1");
        	}else{//大厅，0
        		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");
        	}
        	String serialNo = serialNoAndPasswordMap.get("serialNo");
        	String password = serialNoAndPasswordMap.get("password");
			form.setSerialNo(serialNo);
			form.setPassword(password);
			form.setAcceptNo(serialNo);
    		//生成政务中心统一查询编号 结束
            isNewForm = true;
        }
        YwSrDlzyConvertor.convertFormToVo(form, entity); 
        System.out.println("&&&&&&&&&&&&&&&&&&&&&  后  "+entity.getSqdw());
        System.out.println("&&&&&&&&&&&&&&&&&&&&&  entity.getId() =  "+entity.getId());
        Session session = ywSrDlzyDao.getSessionFactory().openSession();
        session.saveOrUpdate(entity);
        session.flush();
        session.close();
        form.setId(entity.getId());
        
        if (isNewForm) {
            sjclService.updateByNewForm(form.getId());
        }
	}
	
	/**
	 * 保存企业信息，用于企业信息重用,返回企业编号
	 * @param map
	 * @param id
	 * @param form
	 * @param sqdw
	 */
	public Long saveEnterpriseInfo(HttpServletRequest request,Long id,String sqdw,String templateCode){
		//构造map
//		String sqdw = ((String[]) map.get("SR_DLZYSQB_SQDW"))[0];
		
		String qyid=request.getParameter("SR_DLZYSQB_QYBH");
		String qyfzr=request.getParameter("SR_DLZYSQB_FZR");
		String address=request.getParameter("SR_DLZYSQB_SQDW_ADDRESS");//申请单位地址
		String ywlxrtel=request.getParameter("SR_DLZYSQB_SQDW_TEL");//联系电话
		String ywlxr=request.getParameter("SR_DLZYSQB_LXR");//申请单位联系人
		String zsbh=request.getParameter("SR_DLZYSQB_FZH");//证书编号
		Long qybh=null;
		if(StringUtils.isBlank(qyid)){
			YwComQyxxForm form=new YwComQyxxForm();
			form.setSqdw(sqdw);
			form.setQyfzr(qyfzr);
			form.setAddress(address);
			form.setYwlxrtel(ywlxrtel);
			form.setYwlxr(ywlxr);
			form.setTemplateCode(templateCode);
			form.setSqrq(new Date());
			if(zsbh!=null && zsbh.length()>0){
				form.setZsbh(zsbh);
			}
			qybh = ywComQyxxService.saveEnterpriseInfo(form);
		}
		if(qybh!=null){
//			form.setQybh(String.valueOf(qybh));
			this.updateEntityByQyId(qybh,id);//设置企业编号
			return qybh;
		}
		return null;
	}	
	
	/**
	 * 设置企业id
	 * @param qybh
	 * @param id
	 */
	private void updateEntityByQyId(Long qybh, Long id) {
		String sql=" update SR_DLZYSQB_V1 set QYBH="+qybh +" where id="+id ;
		this.ywSrDlzyDao.updateDateBase(sql);
	}
	
	/**
	 * 保存施工单位信息，用于企业信息重用,返回企业编号
	 * @param map
	 * @param id
	 * @param form
	 * @param sqdw
	 */
	public Long saveYwComQyxxTwo(HttpServletRequest request,Long id,String zydw,String templateCode){
		//构造map
		
		String qyid=request.getParameter("SR_DLZYSQB_QYBH_TWO");
		String aqfzr=request.getParameter("SR_DLZYSQB_AQFZR");
		String zydwAddress=request.getParameter("SR_DLZYSQB_ZYDW_ADDRESS");//申请单位地址
		String zydwTel=request.getParameter("SR_DLZYSQB_ZYDW_TEL");//联系电话
		String zydwLxr=request.getParameter("SR_DLZYSQB_ZYDW_LXR");//申请单位联系人
		Long qybhTwo=null;
		YwComQyxxTwoForm form = null;
		if(StringUtils.isBlank(qyid)){
			YwComQyxxTwoForm getForm = ywComQyxxTwoService.getFormBySqdwTwo(zydw, templateCode);
			if(getForm != null){//如果该公司名已经存在，则取出来
				form = getForm;
				this.setYwComQyxxTwoForm(zydw, aqfzr, zydwAddress, zydwTel, zydwLxr, form, templateCode);
				form.setUpdateDateTwo(new Date());
				ywComQyxxTwoService.update(form);
			}else{
				form = new YwComQyxxTwoForm();
				this.setYwComQyxxTwoForm(zydw, aqfzr, zydwAddress, zydwTel, zydwLxr, form, templateCode);
				form.setSqrqTwo(new Date());
				qybhTwo = ywComQyxxTwoService.saveEnterpriseInfo(form);
			}
			
		}else{
			form = ywComQyxxTwoService.get(Long.parseLong(qyid));
			this.setYwComQyxxTwoForm(zydw, aqfzr, zydwAddress, zydwTel, zydwLxr, form, templateCode);
			form.setUpdateDateTwo(new Date());
			ywComQyxxTwoService.update(form);
		}
		
		if(qybhTwo!=null){
			this.updateEntityByIdAndQyxxTwoId(qybhTwo, id);
			return qybhTwo;
		}
		return null;
	}	
	/**
	 * 设置YwComQyxxTwoForm的值
	 * @param zydw
	 * @param aqfzr
	 * @param zydwAddress
	 * @param zydwTel
	 * @param zydwLxr
	 * @param form
	 * @return YwComQyxxTwoForm
	 */
	public YwComQyxxTwoForm setYwComQyxxTwoForm(String zydw,String aqfzr,String zydwAddress,String zydwTel,String zydwLxr,YwComQyxxTwoForm form,String templateCode){
		form.setSqdwTwo(zydw);
		form.setAqfzrTwo(aqfzr);
		form.setAddressTwo(zydwAddress);
		form.setTelTwo(zydwTel);
		form.setLxrTwo(zydwLxr);
		form.setTemplateCodeTwo(templateCode);
		return form;
	}
	
	/**
	 * 设置企业id
	 * @param qybh
	 * @param id
	 */
	private void updateEntityByIdAndQyxxTwoId(Long qybhTwo, Long id) {
		String sql=" update SR_DLZYSQB_V1 set QYBH_TWO="+qybhTwo +" where id="+id;
		this.ywSrDlzyDao.updateDateBase(sql);
	}

	/**
	 * ���Form����Ĳ�ѯ��������ҳ��ѯ
	 */
	@Transactional(readOnly = true)
	public Page<DlzyForm> search(Page<DlzyForm> page, DlzyForm form) {
		// �����µķ�ҳ����
		Page pg = PageUtils.newPageInstance(page);
		
		// ��ѯ��估����
		StringBuffer hql = new StringBuffer("from YwSrDlzy ps where 1=1");
		List values = new ArrayList();
		
		// ��ѯ����
		if(form != null){
			
		}
		
		//����
		hql.append(HqlUtils.buildOrderBy(page, "ps"));
		
		// ִ�з�ҳ��ѯ����
		ywSrDlzyDao.findPage(pg, hql.toString(), values);
		
		// ת��ΪForm�����б?��ֵ��ԭ��ҳ������
		List<DlzyForm> list = YwSrDlzyConvertor.convertVoListToFormList(pg.getResult());
		PageUtils.copy(pg, list, page);
		return page;
	}
	
	/**
	 * ��ݹ��������б�����ҳ��ѯ
	 */
	@Transactional(readOnly = true)
	public Page<DlzyForm> search(Page<DlzyForm> page, List<PropertyFilter> filters) {
		// �����µķ�ҳ����
		Page<YwSrDlzy> pg = PageUtils.newPageInstance(page);
		
		// ������������ҳ���Ҷ���
		ywSrDlzyDao.findPage(pg, filters);
		
		// ת��ΪForm�����б?��ֵ��ԭ��ҳ������
		List<DlzyForm> list = YwSrDlzyConvertor.convertVoListToFormList(pg.getResult());
		PageUtils.copy(pg, list, page);
		return page;
	}
	
	/**
	 * 通过ID号,改变窗口是否可打印受理通知书状态(1为是；0和空为否)
	 * @param acceptNo 受理号
	 * @return Page<YwRqSsgdSqb>
	 */
	public void changeSendAcceptNotice(Long id){
		YwSrDlzy entity = ywSrDlzyDao.get(id);
//		entity.setSendAcceptNotice("1");
		ywSrDlzyDao.save(entity);
	}
	
	/**
	 * 通过ID号,改变窗口是否可打印延期办理结果通知书状态(1为是；0和空为否)
	 * @param id 
	 * @return 
	 */
	public void changeSendYqNotice(Long id){
		YwSrDlzy entity = ywSrDlzyDao.get(id);
//		entity.setSendYqNotice("1");
		ywSrDlzyDao.save(entity);
	}
	
	/**
	 * 根据ID获得对象实体
	 * @param id
	 * @return
	 */  
	public YwSrDlzy getEntity(Long id){
		return ywSrDlzyDao.get(id);
	}
	
	/**
     * 保存对象实体
     * @param ywSrDlzy
     */     
    public void saveEntity(YwSrDlzy ywSrDlzy){
    	ywSrDlzyDao.save(ywSrDlzy);
    }
    
    /**
	 * 获取收件通知书里面的材料列表
	 * @param form
	 * @return
	 */
	public DlzyForm getSjtzsField(DlzyForm form){
		System.out.println("-+++----------++++++++++-----+++"+form.getZylmld());
		form.setSerialNo2(form.getSerialNo());
		form.setPassword2(form.getPassword());
		form.setAcceptNo2(form.getAcceptNo());
		form.setCurDate2(DateUtils.dateTimeToString(new Date(),DateUtils.YEAR_MOUTH_DAY_));
		form.setCurDate4(DateUtils.dateTimeToString(new Date(),DateUtils.YYYY_MM_DD));
		form.setCurDate3(form.getCurDate2());
		form.setCbyw2(form.getCbyw());
		form.setCbyw3(form.getCbyw());
		form.setCbyw4(form.getCbyw());
		form.setSqrq2(form.getTbrq());
		form.setSqrq(form.getTbrq());
		form.setSjr2(form.getSjr());
		System.out.println("+++++++++++"+form.getSjr());
		form.setYwlxr(form.getLxr());
		form.setLxr2(form.getLxr());
		form.setSqdw2(form.getSqdw());
		Long id = form.getId();
		YwComSjcllistForm sjclListForm=new YwComSjcllistForm();
		sjclListForm.setAjid(id);
		sjclListForm.setTplcode(form.getTemplateCode());
        List<YwComSjcllistForm> sjclList = ywComSjcllistService.getList(sjclListForm);
        YwComSjclForm fkForm = new YwComSjclForm();
//        fkForm.setFkid(form.getQyid());
        fkForm.setAjid(id);
        fkForm.setTplcode(form.getTemplateCode());
        List<YwComSjclForm> sjclTpl = ywComSjclService.getList(fkForm);
        for (YwComSjcllistForm listForm : sjclList) {
            boolean hasExists = false;
            for (YwComSjclForm tplForm : sjclTpl) {
                if (tplForm.getTplid() != null && listForm.getId().longValue() == tplForm.getTplid().longValue()) {
                    if (StringUtils.isNotBlank(tplForm.getFilepath())) {
                        listForm.setState("1");
                        listForm.setHasfile("1");
                        listForm.setFilename(tplForm.getFilename());
                        listForm.setFilepath(tplForm.getFilepath());
                        listForm.setFiletype(tplForm.getFiletype());
                    } else {
                        listForm.setState("0");
                        listForm.setHasfile("0");
                    }
                    if (tplForm.getYjs() != null) {
                        listForm.setYjs(Long.valueOf(tplForm.getYjs()));
                    }
                    if (tplForm.getFyjs() != null) {
                        listForm.setFyjs(Long.valueOf(tplForm.getFyjs()));
                    }
                    listForm.setClid(tplForm.getId());
                    if ("1".equals(listForm.getSfdz())) {
                        listForm.setDisabled("1");
                    } else {
                        listForm.setDisabled("0");
                        if (tplForm.getSfdz() == null) {
                            listForm.setSfdz("0");
                        } else {
                            listForm.setSfdz(tplForm.getSfdz());
                        }
                    }
                    hasExists = true;
                }
            }
            if (!hasExists) {
                listForm.setState("0");
                listForm.setHasfile("0");
                if ("1".equals(listForm.getSfdz())) {
                    listForm.setDisabled("1");
                } else {
                    listForm.setDisabled("0");
                }
            }
        }
        if(sjclList.size()>0)
		{
				YwComSjcllistForm sjclForm01=sjclList.get(0);
				form.setTitleRow101(sjclForm01.getTitle());
				form.setTitleRow102(sjclForm01.getTitle());
				form.setFyjsRow101(sjclForm01.getFyjs());
				form.setFyjsRow102(sjclForm01.getFyjs());
				form.setFsRow101(sjclForm01.getYjs()+sjclForm01.getFyjs());
				form.setFsRow102(sjclForm01.getYjs()+sjclForm01.getFyjs());
				if("0".equals(sjclForm01.getSfdz()))
				{
					form.setSfdzRow101("√");
					form.setSfdzRow102("√");
				}else{
					form.setSfdzRow101("√");
					form.setSfdzRow102("√");
				}
				
				YwComSjcllistForm sjclForm02=sjclList.get(1);
				form.setTitleRow201(sjclForm02.getTitle());
				form.setTitleRow202(sjclForm02.getTitle());
				form.setFyjsRow201(sjclForm02.getFyjs());
				form.setFyjsRow202(sjclForm02.getFyjs());
				form.setFsRow201(sjclForm02.getYjs()+sjclForm02.getFyjs());
				form.setFsRow202(sjclForm02.getYjs()+sjclForm02.getFyjs());
				if("0".equals(sjclForm02.getSfdz()))
				{
					form.setSfdzRow201("√");
					form.setSfdzRow202("√");
				}else{
					form.setSfdzRow201("√");
					form.setSfdzRow202("√");
				}
				
				
				YwComSjcllistForm sjclForm03=sjclList.get(2);
				form.setTitleRow301(sjclForm03.getTitle());
				form.setTitleRow302(sjclForm03.getTitle());
				form.setFyjsRow301(sjclForm03.getFyjs());
				form.setFyjsRow302(sjclForm03.getFyjs());
				form.setFsRow301(sjclForm03.getYjs()+sjclForm03.getFyjs());
				form.setFsRow302(sjclForm03.getYjs()+sjclForm03.getFyjs());
				if("0".equals(sjclForm03.getSfdz()))
				{
					form.setSfdzRow301("√");
					form.setSfdzRow302("√");
				}else{
					form.setSfdzRow301("√");
					form.setSfdzRow302("√");
				}
				
				YwComSjcllistForm sjclForm04=sjclList.get(3);
				form.setTitleRow401(sjclForm04.getTitle());
				form.setTitleRow402(sjclForm04.getTitle());
				form.setFyjsRow401(sjclForm04.getFyjs());
				form.setFyjsRow402(sjclForm04.getFyjs());
				form.setFsRow401(sjclForm04.getYjs()+sjclForm04.getFyjs());
				form.setFsRow402(sjclForm04.getYjs()+sjclForm04.getFyjs());
				if("0".equals(sjclForm04.getSfdz()))
				{
					form.setSfdzRow401("√");
					form.setSfdzRow402("√");
				}else{
					form.setSfdzRow401("√");
					form.setSfdzRow402("√");
				}
				
				
				YwComSjcllistForm sjclForm05=sjclList.get(4);
				form.setTitleRow501(sjclForm05.getTitle());
				form.setTitleRow502(sjclForm05.getTitle());
				form.setFyjsRow501(sjclForm05.getFyjs());
				form.setFyjsRow502(sjclForm05.getFyjs());
				form.setFsRow501(sjclForm05.getYjs()+sjclForm05.getFyjs());
				form.setFsRow502(sjclForm05.getYjs()+sjclForm05.getFyjs());
				if("0".equals(sjclForm05.getSfdz()))
				{
					form.setSfdzRow501("√");
					form.setSfdzRow502("√");
				}else{
					form.setSfdzRow501("√");
					form.setSfdzRow502("√");
				}
				
		}
        
        
		return form;
	}
	
	/**
     * 保存政务中心的统一查询编号和密码
     * @param id
     * @param serialNo
     * @param password
     */
    public void saveSerialNoAndPassword(Long id,String serialNo,String password) {
    	YwSrDlzy entity = ywSrDlzyDao.get(id);
    	entity.setSerialNo(serialNo);
    	entity.setPassword(password);
    	ywSrDlzyDao.save(entity);
    }

    /*
     * (non-Javadoc)
     * @see com.augurit.gzcgwsp.smartformCsdlwj.service.IYwDlzyService#insertDays(java.lang.String, java.lang.String, java.lang.String)
     */
	public void insertDays(String days, String taskInstDbid, String acceptNo) {
		String hql=" from DlzyYq where acceptno='"+acceptNo+"'";
		List list=this.ywSrDlzyDao.find(hql);
		Session session=this.ywSrDlzyDao.getSession();
		if(list.size()>0){
			DlzyYq entity=(DlzyYq) list.get(0);
			entity.setYqdays(days);
			session.saveOrUpdate(entity);
		}else{
			DlzyYq entity=new DlzyYq();
			entity.setAcceptno(acceptNo);
			entity.setYqdays(days);
			session.saveOrUpdate(entity);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.smartformCsdlwj.service.IYwDlzyService#getYqDays(java.lang.String, java.lang.String)
	 */
	public String getYqDays(String taskInstDbid, String acceptNo) {
		String hql=" from DlzyYq where acceptno='"+acceptNo+"'";
		List list=this.ywSrDlzyDao.find(hql);
		if(list.size()>0){
			DlzyYq entity=(DlzyYq) list.get(0);
		    return entity.getYqdays();
		}else{
			return "";
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.smartformCsdlwj.service.IYwDlzyService#insertOtherInfo(java.util.Map, java.lang.String, java.lang.String)
	 */
	@Override
	public void insertOtherInfo(Map map, String taskInstDbid, String acceptNo) {
		String id=(String) map.get("id");
		String bjgzfcr=(String) map.get("bjgzfcr");
		String bjgzyy=(String) map.get("bjgzyy");
		String bjgzsj=(String) map.get("bjgzsj");
		String bjgzqd=(String) map.get("bjgzqd");
		String bjslsj=(String) map.get("bjslsj");
		String sldwcbrxm=(String) map.get("sldwcbrxm");
		String bjclqd=(String) map.get("bjclqd");
		String bjsljtdd=(String) map.get("bjsljtdd");
		String yqts=(String) map.get("yqts");
		if(StringUtils.isNotBlank(id)){
			YwSrDlzy entity =  this.ywSrDlzyDao.get(Long.valueOf(id));
			
			if(StringUtils.isNotBlank(bjgzsj)){
				Date bjgzdate;
				try {
					bjgzdate = DateUtilsEX.dateFormate(bjgzsj, "yyyy年MM月dd日");
					entity.setBjgzsj(bjgzdate);//补交告知时间
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			if(StringUtils.isNotBlank(bjslsj)){
				Date bjslsjdate;
				try {
					bjslsjdate = DateUtilsEX.dateFormate(bjslsj, "yyyy年MM月dd日");
					entity.setBjslsj(bjslsjdate);//补交受理时间
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			if(StringUtils.isNotBlank(bjgzfcr)){
				entity.setBjgzfcr(bjgzfcr);//补交告知发出人
			}
			if(StringUtils.isNotBlank(bjgzyy)){
				entity.setBjgzyy(bjgzyy);//补交告知发出人
			}
			if(StringUtils.isNotBlank(bjgzqd)){
				entity.setBjgzqd(bjgzqd);//补交告知发出人
			}
			if(StringUtils.isNotBlank(sldwcbrxm)){
				entity.setSldwcbrxm(sldwcbrxm);//补交告知发出人
			}
			if(StringUtils.isNotBlank(bjclqd)){
				entity.setBjclqd(bjclqd);//补交告知发出人
			}
			if(StringUtils.isNotBlank(bjsljtdd)){
				entity.setBjsljtdd(bjsljtdd);//补交告知发出人
			}
			
			this.insertDays(yqts, taskInstDbid, acceptNo);
			this.ywSrDlzyDao.save(entity);
		}
		
	}
	public String wfBusYslTuih(DlzyForm form,LoginUserForm loginUser) throws Exception {
    	String  loginUserName = loginUser.getUser().getUserName();
    	WfBusInstanceTaskForm taskForm = new WfBusInstanceTaskForm();
		taskForm.setHandleComments("资料不全，不予受理。");
		//把审批状态数据保存到ywWebserviceInfo ，交换给方欣
		ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getYwlxr(), form.getSjr(), form.getSqdw(), 
				form.getBusinessCode(), form.getApprovalNo(), loginUserName, loginUser.getOrg().getOrgName(), "ysl", new Date(), false, "预受理", taskForm);
//		System.out.println("form.getYslThyy() = "+java.net.URLDecoder.decode(form.getYslThyy(),"UTF-8"));
		this.changeYslState(form.getId(), 0L,taskForm.getHandleComments());
		
		//（网办）交换到市民网页
		Map map=exchangeStateService.buildMap(loginUser, null, form.getId().toString(), form.getTemplateCode(), false);
		String durationExpression = wfServiceEX.getDurationExpressionByTemplateCode(form.getTemplateCode());
		ywWebserviceForWbService.setValueAndSaveYwWebserviceForWb(loginUserName,form.getTemplateCode(),
				form.getId().toString(),durationExpression,"001",taskForm.getHandleComments(), map);
    	return null;
    }
	
	@Override
	public void updateAcceptNo(YwSrDlzy form) {
		String hql = "update YwSrDlzy gd set gd.acceptNo='"+form.getAcceptNo()+"',gd.serialNo='"+form.getAcceptNo()+"' where gd.id=:id";
		Query query =this.ywSrDlzyDao.getSession().createQuery(hql);
		query.setLong("id", form.getId());
		query.executeUpdate();
	}

	@Override
	public Page<DlzyForm> searchInputData(Page<DlzyForm> page,
			DlzyForm form,String area) {
		Page pg = PageUtils.newPageInstance(page);
		StringBuffer hql = new StringBuffer("select wj from YwSrDlzy wj , WfBusInstance inst where 1=1 " +
				" and wj.id=inst.masterEntityKey  and inst.masterEntity='YwSrDlzy' and inst.busMemo2='"+area+"'");
		List values = new ArrayList();
		if(form != null){
			if(StringUtils.isNotBlank(form.getSqdw())){
				hql.append(" and wj.sqdw like '%"+form.getSqdw()+"%'");
			}
			if(StringUtils.isNotBlank(form.getAcceptNo())){
				hql.append(" and wj.acceptNo like '%"+form.getAcceptNo()+"%'");
			}
		}
		hql.append(" order by wj.id desc");
        ywSrDlzyDao.findPage(pg, hql.toString(), values);		
		List<DlzyForm> list = YwSrDlzyConvertor.convertVoListToFormList(pg.getResult());
		PageUtils.copy(pg, list, page);
		return page;
	}
	private Jbpm4HistProcinst getProcinstById(Long id){
		String hql=" select proc from Jbpm4HistTask task,WfBusInstance inst,Jbpm4HistProcinst proc where proc.procInstId=task.procInstId" +
		" and proc.procInstId=inst.procInstId and inst.masterEntity='YwSrDlzy' and inst.masterEntityKey="+id;

		List list=this.jbpm4HistTaskDao.find(hql);
		if(list.size()>0){
			Jbpm4HistProcinst proc=(Jbpm4HistProcinst) list.get(0);
			return proc;
		}
		return null;
	}
	private WfBusInstance getInstById(Long id){
		String hql=" select inst from Jbpm4HistTask task,WfBusInstance inst,Jbpm4HistProcinst proc where proc.procInstId=task.procInstId" +
		" and proc.procInstId=inst.procInstId and inst.masterEntity='YwSrDlzy' and inst.masterEntityKey="+id;

		List list=this.jbpm4HistTaskDao.find(hql);
		if(list.size()>0){
			WfBusInstance inst=(WfBusInstance) list.get(0);
			return inst;
		}
		return null;
	}

	@Override
	public void updateJbpmState(DlzyForm form) {
	      //改为已结案件
        if(form.getId()!=null){
        	Jbpm4HistProcinst pro=this.getProcinstById(form.getId());
        	if(!"ended".equals(pro.getState())){
        		pro.setState("ended");
            	jbpm4HistProcinstDao.save(pro);
        	}
        
        }
		
	}

	@Override
	public Long getTaskDbIdById(Long id) {
		String hql=" select task from Jbpm4HistTask task,WfBusInstance inst,Jbpm4HistProcinst proc where proc.procInstId=task.procInstId" +
		" and proc.procInstId=inst.procInstId and inst.masterEntity='YwSrDlzy' and inst.masterEntityKey="+id;
		List list=this.jbpm4HistTaskDao.find(hql);
		if(list.size()>0){
			Jbpm4HistTask task=(Jbpm4HistTask) list.get(0);
			return task.getHistTaskInstDbid();
		}
		return null;
	}

	@Override
	public void deleteMore(String ids) {
		String id[]=ids.split(",");
		for(String dlwjid:id){
			Long wjId=Long.valueOf(dlwjid);
			YwSrDlzy dlwj=ywSrDlzyDao.get(wjId);
			WfBusInstance inst=this.getInstById(wjId);
			Session session=ywSrDlzyDao.getSession();
			session.delete(dlwj);
			session.delete(inst);
		}
	}
	
	/**
	 * 公示
	 * @param form
	 * @param uform
	 * @throws Exception
	 */
	public String gs(DlzyForm form,LoginUserForm uform) throws Exception{
		//读取接口配置信息
		Locale locale = Locale.getDefault(); 
		ResourceBundle localResource = ResourceBundle.getBundle("interfaceExchange", locale);
		String srgsfilepath = localResource.getString("srgsfilepath");//html存放路径
		String srgsxmlpath = localResource.getString("srgsxmlpath");//xml存放路径
		String srgsbackuppath = localResource.getString("srgsbackuppath");//备份存放路径
		if(StringUtils.isBlank(srgsfilepath) || StringUtils.isBlank(srgsxmlpath) ||StringUtils.isBlank(srgsbackuppath)){//没配路径
			return "公示失败，公示文件路径找不到！";
		}
		File srgsfile = new File(srgsfilepath);
		File srgsxmlfile = new File(srgsxmlpath);
		File srgsbackupfile = new File(srgsbackuppath);
		if(!srgsfile .exists()  && !srgsfile .isDirectory()){//如果文件夹不存在   
			return "公示失败，公示文件路径找不到！";
		}else if(!srgsxmlfile .exists()  && !srgsxmlfile .isDirectory()){//如果文件夹不存在   
			return "公示失败，公示文件路径找不到！";
		}else if(!srgsbackupfile .exists()  && !srgsbackupfile .isDirectory()){//如果文件夹不存在   
			return "公示失败，公示文件路径找不到！";
		}
		String lszyArea = "";
//		String zsbh = "";
//		if(StringUtils.isNotBlank(form.getZsbh())){
//			String curYear = form.getCurYear();
//			if(form.getTemplateCode().contains("qx")){
//				zsbh = "区"+curYear+"-"+form.getZsbh();
//			}else{
//				zsbh = "市"+curYear+"-"+form.getZsbh();
//			}
//		}
		String zylmld = "";
		String lxr = "";
		String lxdh = "";
		String zyxz = "";
		String sqdw = "";
		String zydw = "";
		String zyqzrq = "";
		if(StringUtils.isNotBlank(form.getLszyArea())){
			lszyArea = form.getLszyArea();
		}
		if(StringUtils.isNotBlank(form.getZylmld())){
			zylmld = form.getZylmld();
		}
		if(StringUtils.isNotBlank(form.getLxr())){
			lxr = form.getLxr();
		}
		if(StringUtils.isNotBlank(form.getSqdwTel())){
			lxdh = form.getSqdwTel();
		}
		if(StringUtils.isNotBlank(form.getZyxz())){
			zyxz = form.getZyxz();
		}
		if(StringUtils.isNotBlank(form.getSqdw())){
			sqdw = form.getSqdw();
		}
		if(StringUtils.isNotBlank(form.getZydw())){
			zydw = form.getZydw();
		}
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		if(form.getZysjqssj() != null && form.getZysjjssj() != null){
			zyqzrq = sf.format(form.getZysjqssj()) + "至" + sf.format(form.getZysjjssj());
		}
		String templateName = wfServiceEX.getTemplateNameByTemplateCode(form.getTemplateCode());
		SimpleDateFormat sf2 = new SimpleDateFormat("yyyy年MM月dd日");
		String zbrq = sf2.format(new Date());
		
		String sajg = "";//收案机构
		if(StringUtils.isNotBlank(form.getTemplateCode()) && form.getTemplateCode().contains("qx")){
    		sajg = uform.getOrg().getOrgName();
		}else{
			sajg = "广州市城市管理委员会";
		}
		
		StringBuffer sb = new StringBuffer();
		
		sb.append("<center><table width='1000' border='0' cellspacing='2' cellpadding='2'><tr><td>");
		sb.append("<table width='100%' border='0' cellspacing='2' cellpadding='2'><tr>");
		sb.append("<td height='55' bordercolor='#000000' align='left' style='font-family:宋体,华文仿宋;font-size:18px;'>");
		sb.append("<br/><b>"+templateName+"</b><br/></td></tr>");
		sb.append("<tr><td height='55' bordercolor='#000000' align='left' style='font-family:宋体,华文仿宋;font-size:18px;'><br/><b>情况一览表</b><br/><br/></td></tr>");
		sb.append("</table></td></tr><tr><td></td></tr><tr><td>");
		sb.append("			<table width='100%' border='1' cellspacing='0' cellpadding='2' class='tpl_list_ui'><tr id='sfbhTr'>");
		sb.append("                  <td colspan='1' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='center'>许可证号</td>");
		sb.append("                  <td colspan='' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='center'>申请单位</td>");
		sb.append("                  <td bordercolor='#000000' colspan='' height='25' align='center'>占用单位</td>");
		sb.append("                  <td colspan='' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='center'>路段</td>");
		sb.append("                  <td colspan='1' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='center'>占用面积（㎡）</td>");
		sb.append("                  <td bordercolor='#000000' colspan='' height='25' align='center'>现场联系人</td>");
		sb.append("                  <td colspan='' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='center'>手机</td>");
		sb.append("                  <td bordercolor='#000000' colspan='' height='25' align='center'>占用起止日期</td>");
		sb.append("                  <td colspan='' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='center'>类别</td>");
		sb.append("                </tr><tr id='sfbhTr'>");
		sb.append("                  <td width='6%' colspan='1' bordercolor='#000000' colspan='' height='25' align='left'>"+form.getZsbh() +"</td>");
		sb.append("                  <td width='14%' colspan='1' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='left'>"+sqdw+"</td>");
		sb.append("                  <td width='14%' colspan='1' bordercolor='#000000' colspan='' height='25' align='left'>"+zydw+"</td>");
		sb.append("                  <td width='10%' colspan='1' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='left'>"+zylmld +"</td>");
		sb.append("                  <td width='10%' colspan='1' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='left'>"+lszyArea +"</td>");
		sb.append("                  <td width='6%' colspan='1' bordercolor='#000000' colspan='' height='25' align='left'>"+lxr +"</td>");
		sb.append("                  <td width='10%' colspan='1'  bordercolor='#000000' style='padding: 1px 1px 1px 1px;'align='left'>"+lxdh +"</td>");
		sb.append("                  <td width='10%' colspan='1' bordercolor='#000000' colspan='' height='25' align='left'>"+zyqzrq +"</td>");
		sb.append("                  <td width='10%' colspan='1' bordercolor='#000000' style='padding: 1px 1px 1px 1px;' align='left'>"+zyxz+"</td>");
		sb.append("                </tr></table></td></tr>");
		sb.append("<tr><td>制表单位："+sajg+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;制表日期："+zbrq+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;投诉电话：12319</td></tr>");
		sb.append("<tr><td>&nbsp;</td></tr></table></center>");
		this.createXMLUtil(form,templateName,uform,srgsxmlpath,srgsbackuppath);
		String filePath = srgsfilepath + form.getAcceptNo() + ".html";//生成html,存放
		File file = new File(filePath);
		FileWriter fw = new FileWriter(file);
		fw.write(sb.toString());
		fw.flush();
		fw.close();
		
		String backupfilePath = srgsbackuppath + form.getAcceptNo() + ".html";//生成备份html,存放
		File backupfile = new File(backupfilePath);
		FileWriter backupfw = new FileWriter(backupfile);
		backupfw.write(sb.toString());
		backupfw.flush();
		backupfw.close();
		return "";
	}
	
	/**
	 * 创建公示xml
	 */
	public void createXMLUtil(DlzyForm form,String title,LoginUserForm uform,String srgsxmlpath,String srgsbackuppath) throws Exception{
		 Document doc = this.createXML(form,title,uform);  
		 if(doc!=null){
			OutputFormat format = OutputFormat.createPrettyPrint();   
			format.setEncoding("UTF-8");  
			FileOutputStream fos = new FileOutputStream(srgsxmlpath + "000003_02_" + form.getAcceptNo() + ".xml");   //生成xml，存放   
			XMLWriter writer = new XMLWriter(fos, format);
			//writer.setEscapeText(false); 
		    writer.write(doc);   
			writer.close();
			
			FileOutputStream backupfos = new FileOutputStream(srgsbackuppath + "000003_02_" + form.getAcceptNo() + ".xml");   //生成备份xml，存放   
			XMLWriter backupwriter = new XMLWriter(backupfos, format);
			backupwriter.write(doc);   
			backupwriter.close();
		 }  
	}
 
	/**
	 * 生成公示xml
	 * @param status
	 * @return
	 */
	public  Document createXML(DlzyForm form,String title,LoginUserForm uform) throws Exception{   
	   	Document doc = DocumentHelper.createDocument();   
        Element root = doc.addElement("exchange_data");   
        Element head = root.addElement("head");   
        head.addElement("sender").addText("000003"); 
        Element receivers = head.addElement("receivers"); 
        receivers.addElement("receiver").addText("000001");
        //获取交换流水号
    	Date date2 = new Date();
		SimpleDateFormat myFmt = new SimpleDateFormat("yyMMddHHmmSS");
		String dateStr = myFmt.format(date2);
		String sn = "000003" + dateStr + form.getAcceptNo();
        head.addElement("sn").addText(sn); 
        head.addElement("businessCode").addText("02"); 
        head.addElement("sendTime").addText(DateUtilsEX.dateFormate(new Date(), "yyyy-MM-dd HH:mm:ss"));
        head.addElement("version").addText("1.0"); 
        head.addElement("priority").addText("1");
        String ifPublic = this.getIfPublicById(form.getId());
        String operation = "";
        if(StringUtils.isBlank(ifPublic)){
        	ifPublic = "new";
        	operation = "I";
        }else{
        	ifPublic = "update";
        	operation = "U";
        }
        this.changeIfPublicById(form.getId(), ifPublic);
        
        Element body = root.addElement("body");   
        Element data = body.addElement("data");
        Element tableData = data.addElement("tableData");
        Element DataSet = tableData.addElement("DataSet");
        
        Element RecordData = DataSet.addElement("RecordData");
        Element UnitData = RecordData.addElement("UnitData");
        UnitData.addElement("UnitIDName").addText("content_table");
        Element UnitValue = UnitData.addElement("UnitValue");
        Element content = UnitValue.addElement("content");
        String sajg = "";//收案机构
		if(StringUtils.isNotBlank(form.getTemplateCode()) && form.getTemplateCode().contains("qx")){
    		sajg = uform.getOrg().getOrgName();
		}else{
			sajg = "广州市城市管理委员会";
		}
        content.addElement("orgName").addText(sajg);
        content.addElement("publishUserName").addText(uform.getUser().getUserName());
        content.addElement("categoryId").addText("FDR4HA4XB81LKJ3QPESAD5DCEH307SP6");
        content.addElement("contentIdFromOA").addText(form.getAcceptNo());
        content.addElement("operation").addText(operation);
        content.addElement("type").addText("2");
        content.addElement("title").addText("");
        content.addElement("title2").addText("");
        content.addElement("author").addText("");
        content.addElement("editor").addText("");
        content.addElement("publishDate").addText(DateUtilsEX.dateFormate(new Date(), "yyyy-MM-dd HH:mm:ss"));
        content.addElement("source").addText("");
        content.addElement("priority").addText("0");
        content.addElement("priorityStartDate").addText("");
        content.addElement("priorityEndDate").addText("");
        content.addElement("memo").addText("");
        content.addElement("titleImage").addText("");
        content.addElement("publicType").addText("0");
        content.addElement("contentType").addText("06");
        content.addElement("publicYear").addText(DateUtilsEX.dateFormate(new Date(), "yyyy"));
        
        Element contentFiles = data.addElement("contentFiles");
        contentFiles.addElement("contentFile").addText(form.getAcceptNo()+".html");
        data.addElement("attachments").addText("");
        return doc;
	}
	
	/**
	 * 获取是否公示判断字段
	 * @param id
	 * @return
	 */
	public String getIfPublicById(Long id) throws Exception {
		String ifPublic = "";
		String sql = "select t.if_public from SR_DLZYSQB_V1 t where t.id="+id;
		SQLQuery query = ywSrDlzyDao.getSession().createSQLQuery(sql);
		if(query != null){
			if(query.list().size()>0){
				ifPublic = (String)query.list().get(0);
				System.out.println("ifPublic = "+ifPublic);
			}
		}
		return ifPublic;
	}
	
	/**
	 * 更新是否公示判断字段
	 * @param id
	 * @return
	 */
	public String changeIfPublicById(Long id,String state) throws Exception {
		String sql = "update SR_DLZYSQB_V1 t set t.if_public='"+state+"' where t.id="+id;
		SQLQuery query = ywSrDlzyDao.getSession().createSQLQuery(sql);
		query.executeUpdate();
		return null;
	}

	@Override
	public void savesf(Map map, String taskInstDbid, DlzyForm form) {
		YwSrDlzy entity=ywSrDlzyDao.get(form.getId());
		if(entity!=null){
			entity.setFph(form.getFph());
			entity.setSfje(form.getSfje());
			entity.setSfbh(form.getSfbh());
			ywSrDlzyDao.save(entity);
		}
		
	}
}
